package com.my.study.hutool.core;

import cn.hutool.core.bean.BeanPath;
import com.my.study.hutool.core.bean.ExamInfoDict;
import com.my.study.hutool.core.bean.UserInfoDict;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: yidujun
 * @create: 2021/06/30 14:03
 */
public class TestBeanPath {

    public static void main(String[] args) {
        Map<String, Object> tempMap = new HashMap<>();
        tempMap.put("userInfo", getUserInfo());
        tempMap.put("flag", 1);

        // 获取用户第一门考试ID
        BeanPath resolver = new BeanPath("userInfo.examInfoDict[0].id");
        Object o = resolver.get(tempMap);
        System.out.println(o);
    }

    /**
     * 用户信息
     *
     * @return UserInfoDict
     * @see UserInfoDict
     */
    private static UserInfoDict getUserInfo() {
        UserInfoDict userInfoDict = new UserInfoDict();
        userInfoDict.setId(1);
        userInfoDict.setPhotoPath("yx.mm.com");
        userInfoDict.setRealName("张三");
        userInfoDict.setExamInfoDict(getExamInfos());

        return userInfoDict;
    }

    /**
     * 考试信息列表
     *
     * @return List
     * @see ExamInfoDict
     */
    private static List<ExamInfoDict> getExamInfos() {
        ExamInfoDict examInfoDict = new ExamInfoDict();
        examInfoDict.setId(1);
        examInfoDict.setExamType(0);
        examInfoDict.setAnswerIs(1);

        ExamInfoDict examInfoDict1 = new ExamInfoDict();
        examInfoDict1.setId(2);
        examInfoDict1.setExamType(0);
        examInfoDict1.setAnswerIs(0);

        ExamInfoDict examInfoDict2 = new ExamInfoDict();
        examInfoDict2.setId(3);
        examInfoDict2.setExamType(1);
        examInfoDict2.setAnswerIs(0);

        List<ExamInfoDict> examInfoDicts = new ArrayList<>();
        examInfoDicts.add(examInfoDict);
        examInfoDicts.add(examInfoDict1);
        examInfoDicts.add(examInfoDict2);

        return examInfoDicts;
    }

}
